<template>
    <div class="meList">
        <div class="meList-top">
            <div class="title">最近播放<span>共{{playlist.length}}首</span></div>
        </div>
        <div class="musicList">
        <div class="music" v-for="(item,i) in playlist" :key="i" @click="setplay(item.song)">
            <div class="bh">{{i+1}}.</div>
            <svg class="icon" aria-hidden="true">
                <use xlink:href="#icon-bofang3"></use>
            </svg>
            <div class="title">{{item.song.name}}</div>
            <div class="author" v-for="(time,k) in item.song.ar" :key="k">
                <p v-if="k<1">{{time.name}}</p>
            </div>
        </div>
        </div>
    </div>
</template>
<script>
import { setRecord } from '@/api/index.js'
import { Toast } from 'vant'
export default {
  data: function () {
    return {
      playlist: []
    }
  },
  mounted: async function () {
    const setres = await setRecord(this.$store.state.user.account.id)
    this.playlist = setres.data.allData
    if (this.$store.state.isuser === '登录成功') {
      Toast({
        message: '登录成功!',
        position: 'top'
      })
      this.$store.commit('setIsUser', 'false')
    }
    // console.log(this.playlist)
  },
  methods: {
    setplay (item) {
      console.log(item)
      this.$store.commit('pushPlaylist', item)
      this.$store.commit('setPlayIndex', this.$store.state.playlist.length - 1)
    }
  }
}
</script>
<style lang="less" scoped>
.meList{
    width: 7.5rem;
    .meList-top{
        width: 7.1rem;
        margin: 0 auto;
        padding-bottom: 0.1rem;
        border-bottom:2px solid red;
        .title{
            font-weight: 900;
            color:gray;
            font-size: 0.4rem;
            span{
                font-size: 0.3rem;
                color: #ccc;
                margin-left: 0.2rem;
            }
        }
    }
    .musicList{
        height: 7.6rem;
        overflow: auto;
        margin-bottom: 1.2rem;
    }
    .music{
        display: flex;
        align-items: center;
        height: 1rem;
        width: 7.1rem;
        margin: 0 auto;
        .bh{
            font-size: 0.4rem;
            width: 0.6rem;
        }
        .icon{
            fill: gray;
            width: 0.4rem;
            height: 0.4rem;
            margin: 0 0.2rem;
        }
        .title{
            width: 2.8rem;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }
        .author{
            color: #ccc;
            margin: 0 0.2rem;
            white-space:nowrap
        }
    }
}
</style>
